<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>segment_view</title>
<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../../index.html" title="Chapter 1. Geometry">
<link rel="up" href="../views.html" title="Views">
<link rel="prev" href="box_view.html" title="box_view">
<link rel="next" href="closeable_view.html" title="closeable_view">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="box_view.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../views.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="closeable_view.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="geometry.reference.views.segment_view"></a><a class="link" href="segment_view.html" title="segment_view">segment_view</a>
</h4></div></div></div>
<p>
          <a class="indexterm" name="idm100465"></a>
Makes a segment behave like a linestring or a range.
        </p>
<h6>
<a name="geometry.reference.views.segment_view.h0"></a>
          <span class="phrase"><a name="geometry.reference.views.segment_view.description"></a></span><a class="link" href="segment_view.html#geometry.reference.views.segment_view.description">Description</a>
        </h6>
<p>
          Adapts a segment to the Boost.Range concept, enabling the user to iterate
          the two segment points. The segment_view is registered as a LineString
          Concept
        </p>
<h6>
<a name="geometry.reference.views.segment_view.h1"></a>
          <span class="phrase"><a name="geometry.reference.views.segment_view.model_of"></a></span><a class="link" href="segment_view.html#geometry.reference.views.segment_view.model_of">Model
          of</a>
        </h6>
<p>
          <a class="link" href="../concepts/concept_linestring.html" title="Linestring Concept">LineString
          Concept</a>
        </p>
<h6>
<a name="geometry.reference.views.segment_view.h2"></a>
          <span class="phrase"><a name="geometry.reference.views.segment_view.synopsis"></a></span><a class="link" href="segment_view.html#geometry.reference.views.segment_view.synopsis">Synopsis</a>
        </h6>
<p>
</p>
<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Segment</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">segment_view</span>
<span class="special">{</span>
  <span class="comment">// ...</span>
<span class="special">};</span>
</pre>
<p>
        </p>
<h6>
<a name="geometry.reference.views.segment_view.h3"></a>
          <span class="phrase"><a name="geometry.reference.views.segment_view.template_parameter_s_"></a></span><a class="link" href="segment_view.html#geometry.reference.views.segment_view.template_parameter_s_">Template
          parameter(s)</a>
        </h6>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                  <p>
                    Parameter
                  </p>
                </th>
<th>
                  <p>
                    Description
                  </p>
                </th>
</tr></thead>
<tbody><tr>
<td>
                  <p>
                    typename Segment
                  </p>
                </td>
<td>
                  <p>
                    A type fulfilling the Segment Concept
                  </p>
                </td>
</tr></tbody>
</table></div>
<h6>
<a name="geometry.reference.views.segment_view.h4"></a>
          <span class="phrase"><a name="geometry.reference.views.segment_view.constructor_s_"></a></span><a class="link" href="segment_view.html#geometry.reference.views.segment_view.constructor_s_">Constructor(s)</a>
        </h6>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                  <p>
                    Function
                  </p>
                </th>
<th>
                  <p>
                    Description
                  </p>
                </th>
<th>
                  <p>
                    Parameters
                  </p>
                </th>
</tr></thead>
<tbody><tr>
<td>
                  <p>
</p>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">segment_view</span><span class="special">(</span><span class="identifier">Segment</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">segment</span><span class="special">)</span></pre>
<p>
                  </p>
                </td>
<td>
                  <p>
                    Constructor accepting the segment to adapt.
                  </p>
                </td>
<td>
                  <p>
                    <span class="bold"><strong>Segment const &amp;</strong></span>: <span class="emphasis"><em>segment</em></span>:
                  </p>
                </td>
</tr></tbody>
</table></div>
<h6>
<a name="geometry.reference.views.segment_view.h5"></a>
          <span class="phrase"><a name="geometry.reference.views.segment_view.member_function_s_"></a></span><a class="link" href="segment_view.html#geometry.reference.views.segment_view.member_function_s_">Member
          Function(s)</a>
        </h6>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                  <p>
                    Function
                  </p>
                </th>
<th>
                  <p>
                    Description
                  </p>
                </th>
<th>
                  <p>
                    Parameters
                  </p>
                </th>
<th>
                  <p>
                    Returns
                  </p>
                </th>
</tr></thead>
<tbody>
<tr>
<td>
                  <p>
</p>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">const_iterator</span> <span class="identifier">begin</span><span class="special">()</span></pre>
<p>
                  </p>
                </td>
<td>
                </td>
<td>
                </td>
<td>
                </td>
</tr>
<tr>
<td>
                  <p>
</p>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">const_iterator</span> <span class="identifier">end</span><span class="special">()</span></pre>
<p>
                  </p>
                </td>
<td>
                </td>
<td>
                </td>
<td>
                </td>
</tr>
</tbody>
</table></div>
<h6>
<a name="geometry.reference.views.segment_view.h6"></a>
          <span class="phrase"><a name="geometry.reference.views.segment_view.header"></a></span><a class="link" href="segment_view.html#geometry.reference.views.segment_view.header">Header</a>
        </h6>
<p>
          Either
        </p>
<p>
          <code class="computeroutput"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
        </p>
<p>
          Or
        </p>
<p>
          <code class="computeroutput"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">/</span><span class="identifier">views</span><span class="special">/</span><span class="identifier">segment_view</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
        </p>
<h6>
<a name="geometry.reference.views.segment_view.h7"></a>
          <span class="phrase"><a name="geometry.reference.views.segment_view.complexity"></a></span><a class="link" href="segment_view.html#geometry.reference.views.segment_view.complexity">Complexity</a>
        </h6>
<p>
          Compile time
        </p>
<h6>
<a name="geometry.reference.views.segment_view.h8"></a>
          <span class="phrase"><a name="geometry.reference.views.segment_view.example"></a></span><a class="link" href="segment_view.html#geometry.reference.views.segment_view.example">Example</a>
        </h6>
<p>
          Shows usage of the Boost.Range compatible view on a box
        </p>
<p>
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>

<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>


<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
<span class="special">{</span>
    <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">model</span><span class="special">::</span><span class="identifier">segment</span>
        <span class="special">&lt;</span>
            <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">model</span><span class="special">::</span><span class="identifier">point</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">,</span> <span class="number">2</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">cs</span><span class="special">::</span><span class="identifier">cartesian</span><span class="special">&gt;</span>
        <span class="special">&gt;</span> <span class="identifier">segment_type</span><span class="special">;</span>

    <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">segment_view</span><span class="special">&lt;</span><span class="identifier">segment_type</span><span class="special">&gt;</span> <span class="identifier">segment_view</span><span class="special">;</span>

    <span class="identifier">segment_type</span> <span class="identifier">segment</span><span class="special">;</span>
    <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">assign_values</span><span class="special">(</span><span class="identifier">segment</span><span class="special">,</span> <span class="number">0</span><span class="special">,</span> <span class="number">0</span><span class="special">,</span> <span class="number">1</span><span class="special">,</span> <span class="number">1</span><span class="special">);</span>

    <span class="identifier">segment_view</span> <span class="identifier">view</span><span class="special">(</span><span class="identifier">segment</span><span class="special">);</span>

    <span class="comment">// Iterating over the points of this segment</span>
    <span class="keyword">for</span> <span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">range_iterator</span><span class="special">&lt;</span><span class="identifier">segment_view</span> <span class="keyword">const</span><span class="special">&gt;::</span><span class="identifier">type</span> <span class="identifier">it</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">begin</span><span class="special">(</span><span class="identifier">view</span><span class="special">);</span>
        <span class="identifier">it</span> <span class="special">!=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">end</span><span class="special">(</span><span class="identifier">view</span><span class="special">);</span> <span class="special">++</span><span class="identifier">it</span><span class="special">)</span>
    <span class="special">{</span>
        <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">" "</span> <span class="special">&lt;&lt;</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">dsv</span><span class="special">(*</span><span class="identifier">it</span><span class="special">);</span>
    <span class="special">}</span>
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>

    <span class="comment">// Note that a segment_view is tagged as a linestring, so supports length etc.</span>
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"Length: "</span> <span class="special">&lt;&lt;</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">length</span><span class="special">(</span><span class="identifier">view</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>

    <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
<span class="special">}</span>
</pre>
<p>
        </p>
<p>
          Output:
        </p>
<pre class="programlisting">(0, 0) (1, 1)
Length: 1.41421
</pre>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2009-2021 Barend Gehrels,
      Bruno Lalande, Mateusz Loskot, Adam Wulkiewicz, Oracle and/or its affiliates<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="box_view.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../views.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="closeable_view.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
